//
//  RCMerchantPicturesDataModel.m
//  RocketProject
//
//  Created by Wu Chengwei on 13-9-29.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCMerchantPicturesDataModel.h"
#import "FrameworkRelativeDefines.h"
#import "NSArray+EX.h"

@implementation RCMerchantPictureItem

@synthesize photoID = _photoID;
@synthesize typeID = _typeID;
@synthesize photoPicUrl = _photoPicUrl;
@synthesize photoTitle = _photoTitle;
@synthesize photoPrice = _photoPrice;
@synthesize photoScore = _photoScore;
@synthesize userName = _userName;
@synthesize photoDateTime = _photoDateTime;

-(id)init{
    self = [super init];
    if (self) {
        _photoID = nil;
        _typeID = nil;
        _photoTitle = nil;
        _photoPicUrl = nil;
        _photoBigPicUrl = nil;
        _userName = nil;
        _photoDateTime = nil;
        _photoPrice = 0.0f;
        _photoScore = 0.0f;
    }
    return self;
}

-(void)dealloc{
    
    self.photoTitle = nil;
    self.photoID = nil;
    self.typeID = nil;
    self.photoPicUrl = nil;
    self.photoDateTime = nil;
    self.photoBigPicUrl = nil;
    self.userName = nil;
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    RCMerchantPictureItem *retObject = nil;
    retObject = [[RCMerchantPictureItem alloc]init];
    if (nil == retObject) {
        return nil;
    }
    retObject.photoID = [data stringValueForKey:@"photoid" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.typeID = [data stringValueForKey:@"typeid" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.photoTitle = [data stringValueForKey:@"title" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.photoPicUrl = [data stringValueForKey:@"picurl" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.photoBigPicUrl = [data stringValueForKey:@"bigpicurl" defaultValue:nil operation:NSStringOperationTypeTrim];
    if (nil == retObject.photoBigPicUrl) {
        retObject.photoBigPicUrl = retObject.photoPicUrl;
    }
    retObject.userName = [data stringValueForKey:@"username" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.photoDateTime = [data stringValueForKey:@"datetime" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.photoPrice = [data intValueForKey:@"price" defaultValue:0];
    retObject.photoScore = [data intValueForKey:@"score" defaultValue:0];
    return [retObject autorelease];
}

@end

@implementation rcMerchantPictureSubAlbum

@synthesize typeID = _typeID;
@synthesize typeName = _typeName;
@synthesize hasChild = _hasChild;
@synthesize pn = _pn;
@synthesize rn = _rn;
@synthesize total = _total;
@synthesize photoItemArray = _photoItemArray;

-(id)init{
    self = [super init];
    if (self) {
        _typeID = nil;
        _typeName = nil;
        _hasChild = NO;
        _pn = 0;
        _rn = 0;
        _total = 0;
        _photoItemArray = nil;
    }
    return self;
}

-(void)dealloc{
    self.typeID = nil;
    self.typeName = nil;
    self.photoItemArray = nil;
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    NSString *typeid = [data stringValueForKey:@"typeid" defaultValue:nil operation:NSStringOperationTypeTrim];
    if (nil == typeid) {
        data = [data dictionaryValueForKey:@"data" defaultValue:nil];
    }
    
    rcMerchantPictureSubAlbum *retObject = nil;
    retObject = [[rcMerchantPictureSubAlbum alloc]init];
    if (nil == retObject) {
        return nil;
    }
    retObject.typeID = [data stringValueForKey:@"typeid" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.typeName = [data stringValueForKey:@"name" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.pn = [data intValueForKey:@"pn" defaultValue:0];
    retObject.rn = [data intValueForKey:@"rn" defaultValue:0];
    retObject.total = [data intValueForKey:@"total" defaultValue:0];
    NSInteger child = [data intValueForKey:@"child" defaultValue:0];
    if (child == 1) {
        retObject.hasChild = YES;
    }else{
        retObject.hasChild = NO;
    }
    NSArray *itemDictArray = [data arrayValueForKey:@"items" defaultValue:nil];
    if (itemDictArray != nil && [itemDictArray count] > 0) {
        NSMutableArray *tempArray = [[NSMutableArray alloc]initWithCapacity:[itemDictArray count]];
        for (int i =0 ; i < [itemDictArray count]; i++) {
            NSDictionary *itemDict = [itemDictArray safeObjectAtIndex:i];
            if (nil == itemDictArray) {
                continue;
            }
            RCMerchantPictureItem *item = [RCMerchantPictureItem parseDataFromJSON:itemDict];
            if (nil == item) {
                continue;
            }
            [tempArray addObject:item];
        }
        
        retObject.photoItemArray = [NSArray arrayWithArray:tempArray];
        [tempArray release];
    }
    
    return [retObject autorelease];
}

@end

@implementation RCMerchantPicturesDataModel

@synthesize albumArray = _albumArray;

-(id)init{
    self = [super init];
    if (self) {
        _albumArray = nil;
    }
    return self;
}

-(void)dealloc{
    self.albumArray = nil;
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    
    NSArray *dictArray = [data arrayValueForKey:@"data" defaultValue:nil];
    if (nil == dictArray || [dictArray count] == 0) {
        return nil;
    }
    
    RCMerchantPicturesDataModel *retObject = nil;
    retObject = [[RCMerchantPicturesDataModel alloc]init];
    if (nil == retObject) {
        return nil;
    }
    
    NSMutableArray *tempArray = [[NSMutableArray alloc]initWithCapacity:[dictArray count]];
    for (int i = 0; i < [dictArray count]; i++) {
        NSDictionary *itemDict = [dictArray safeObjectAtIndex:i];
        if (nil == itemDict) {
            continue;
        }
        rcMerchantPictureSubAlbum *item = [rcMerchantPictureSubAlbum parseDataFromJSON:itemDict];
        if (nil == item) {
            continue;
        }
        [tempArray addObject:item];
    }
    retObject.albumArray = [NSArray arrayWithArray:tempArray];
    [tempArray release];
    return [retObject autorelease];
}

@end
